// pages/student/profile/profile.js
import { logout } from '../../../utils/auth.js'

Page({
  data: {
    userInfo: null,
    menuItems: [
      { icon: '📚', text: '我的课程', url: '/pages/student/my-course/my-course' },
      { icon: '📖', text: '观看记录', url: '/pages/student/watch-record/watch-record' },
      { icon: '📝', text: '练习记录', url: '/pages/student/practice-record/practice-record' },
      { icon: '🛒', text: '我的订单', url: '/pages/student/order/order' },
      { icon: '⭐', text: '我的收藏', url: '/pages/student/favorite/favorite' },
      { icon: '👤', text: '个人信息', url: '/pages/student/edit-profile/edit-profile' }
    ]
  },
  onLoad() {
    this.loadUserInfo()
  },
  onShow() {
    this.loadUserInfo()
  },
  loadUserInfo() {
    const userInfo = wx.getStorageSync('userInfo')
    this.setData({ userInfo })
  },
  navigateTo(e) {
    const url = e.currentTarget.dataset.url
    if (url) {
      wx.navigateTo({ url })
    }
  },
  handleLogout() {
    wx.showModal({
      title: '退出登录',
      content: '确定要退出登录吗？',
      success: (res) => {
        if (res.confirm) {
          logout()
        }
      }
    })
  }
})
